<template>
  <div>
    <!--本体列表，数据 -->
    <div class="table-body mt-20">
      <div class="table-body-box">
        <el-table
            ref="multipleTable"
            :data="arryList"
            :stripe="tableStyle.tableStripe"
            :border="tableStyle.tableBorder"
            tooltip-effect="dark"
            style="width: 100%"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c">
          <el-table-column
              prop="book_name"
              label="图书名称">
            <template slot-scope="scope">
              <span>{{ scope.row.book.name }}</span>
            </template>
          </el-table-column>
          <el-table-column
              label="作者"
              width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.book ? scope.row.book.editor : '' }}</span>
            </template>
          </el-table-column>
          <el-table-column
              label="类目">
            <template slot-scope="scope">
              <span>{{ scope.row.book ? scope.row.book.bookCatName : '' }}</span>
            </template>
          </el-table-column>
          <el-table-column
              label="存放位置"
              width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.book ? scope.row.book.position : '' }}</span>
            </template>
          </el-table-column>
          <el-table-column
              prop="code"
              label="条形码"
              width="200">
          </el-table-column>
          <el-table-column
              label="借阅人员"
              width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.book ? scope.row.examine.realname : '' }}</span>
            </template>
          </el-table-column>
          <el-table-column
              prop="create_time"
              label="申请时间"
              width="110">
            <template slot-scope="scope">
              {{ scope.row.create_time }}
            </template>

          </el-table-column>
          <el-table-column
              prop="return_time"
              label="预还时间"
              width="110">
            <template slot-scope="scope">
              <span
                  :class="Date.parse(scope.row.return_time) > new Date()?'':'redColor'">{{
                  scope.row.return_time
                }}</span>
            </template>
          </el-table-column>
          <el-table-column
              prop="actual_return_time"
              label="实际还书时间"
              width="160"
              key="1">
          </el-table-column>
          <el-table-column
              label="图书状态"
              width="80">
            <template slot-scope="scope">
              已还
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!--工具条 分页-->
    <el-col :span="24" class="toolbar">
      <el-pagination
          background
          layout="prev, pager, next"
          :total="page.total"
          :page-size="page.pagesize"
          @current-change="handleSizeChange">
      </el-pagination>
    </el-col>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'

export default {
  props:['searchForm'],
  watch:{
    searchForm(){
      console.log('searchForm变了:',this.searchForm)
      this.searchData = this.searchForm;
      this.detailBox()
    }
  },
  data() {
    return {
      // 设置table样式
      tableStyle: tableoption,
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [], // 数据列表
      // 搜索组件
      searchData: {}
    }
  },
  created() {
    console.log('创建了',this.searchData)
    // this.detailBox()
  },
  methods: {
    async detailBox() {
      let n = this;
      this.searchData.p = this.page.pageindex;
      this.searchData.status = 2; // 状态0申请中1待归还2已归还 3驳回
      let data = await this.$fetch(this.api.admin_read_index, this.searchData)
      console.log('请求数据了啊', data)
      if (!data.code) {
        for (let i in data.list.data) {
          data.list.data[i].create_time = data.list.data[i].create_time.split(' ')[0]
          data.list.data[i].examine_time = data.list.data[i].examine_time.split(' ')[0]
          data.list.data[i].actual_return_time = data.list.data[i].actual_return_time.split(' ')[0]
        }
        this.arryList = this.getJson(data.list.data);
        this.page.total = data.list.total;
        this.$emit('getNewNumber',data.number)
      }
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.detailBox()
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
  },
  mounted() {
  }
}
</script>
